package com.platform.qujia.service.impl;

import com.platform.qujia.pojo.WxMessageTemplate;
import com.platform.qujia.service.WxTemplateParamsGeneral;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

@Component("wxTemplateRechargeSuccess")
public class WxTemplateRechargeSuccessParams implements WxTemplateParamsGeneral {

    /**
     * 充值账号：{{keyword1.DATA}}
     * 充值金额：{{keyword2.DATA}}
     * 充值方式：{{keyword3.DATA}}
     * 充值时间：{{keyword4.DATA}}
     *
     * @return
     */
    @Override
    public void setWxTemplateContent(List<String> contents, Map<String, String> templateParams, Map<String, Map<String, String>> data) {
        if (contents.contains("充值卡号")) {
            data.put("character_string9", Collections.singletonMap("value", templateParams.get("customerNo")));
        }
        if (contents.contains("充值金额")) {
            data.put("amount2", Collections.singletonMap("value", templateParams.get("amt")));
        }
        if (contents.contains("赠送金额")) {
            data.put("amount7", Collections.singletonMap("value", templateParams.get("presentAmt")));
        }
        if (contents.contains("余额")) {
            data.put("amount3", Collections.singletonMap("value", templateParams.get("balance")));
        }
        if (contents.contains("充值时间")) {
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            data.put("time5", Collections.singletonMap("value", formatter.format(LocalDateTime.now())));
        }
    }
}
